package com.example.demo.checkReport.service.impl;

import com.example.demo.checkReport.entity.Cost;
import com.example.demo.checkReport.mapper.CostMapper;
import com.example.demo.checkReport.service.CostService;
import com.example.demo.common.ResponseData;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * VIEW 服务实现类
 * </p>
 *
 * @author beyong
 * @since 2021-05-29
 */
@Service
public class CostServiceImpl extends ServiceImpl<CostMapper, Cost> implements CostService {

	@Autowired
	private CostMapper costMapper;
	
	/**
	 * 根据条件查询 成本核算 的物料信息
	 */
	@Override
	public ResponseData getCost(String purpose, String department, String year, String month) {
		
		List<Cost> costResults = new ArrayList<Cost>();
		String countResult;
		
		try {
			
			costResults = costMapper.cost(purpose, department, year, month);
			
			countResult = costMapper.getCostCount(purpose, department, year, month);
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return ResponseData.buildError("error！");
		}
		
		return ResponseData.buildOk(countResult, costResults);
	}

}
